package util;

import java.util.Map;

/**
 * @author wanglei
 * @date 2021/10/13
 * */
public class MapUtil {
    /**
     * map转str
     *
     * @author wanglei
     * @date 2021/10/13
     * */
    public static String map2str(Map<String, String[]> map) {
        StringBuilder sb = new StringBuilder();
        if (map.size() > 0) {
            for (Map.Entry<String, String[]> entry : map.entrySet()) {
                String[] values = entry.getValue();
                StringBuilder vb = new StringBuilder();
                String value = "";
                if(values != null && values.length>0){
                    for(String s : values){
                        vb.append(s).append(",");
                    }
                    value = vb.substring(0, vb.length()-1);
                }
                sb.append(entry.getKey()).append("=").append(value).append("&");
            }
            return sb.substring(0, sb.length()-1);
        }
        else{
            return "";
        }
    }
}
